home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
016a
/
4date.zip
/
4DATE.BTM
next >
Wrap
Text File
|
1991-11-07
|
8KB
|
301 lines
@echo off
: 4DATE - implements various useful date functions.
:
: Usage:
: 4DATE [date-function argument...]
:
: Returns:
: 4DATE functions set the environment variable
: "_$" to the return value of the function.
: Primitive functions ONLY set "_$", higher
: level interfaces display results.
:
: History:
: 07-Nov-91 MGiguere DOW now uses 4DOS %@INT[] func.
: 31-Oct-91 MGiguere %_date default for DDATE & DIFF
: 25-Oct-91 MGiguere Added Day-Of-Week function.
: 24-Oct-91 MGiguere Created.
:
iff "%debug" NE "" then
echo 4DATE:
echo on
endiff
iff "%1" EQ "" then
gosub HELP
else
gosub %1
endiff
quit
:CJUL
: CJUL - 4DATE CJUL date
: Compute & Return the "Julian" day of year for the specified date.
:
: Primitive function.
:
set _$=%@eval[1+%@date[%2]-%@date[01-01-%@substr[%2,6]]]
return
:DDATE
: DDATE - 4DATE DDATE integer [aDate]
: DeltaDate returns the actual date for a given
: number of days before or after a give date.
: If aDate not specified todays date is default.
:
: Primitive function.
:
iff .%3==. then
set _$=%@makedate[%@eval[%@date[%_date]+%2]]
else
set _$=%@makedate[%@eval[%@date[%3]+%2]]
endiff
return
:DIFF
: DIFF - DIFF date1 [date2]
: compute the difference between two dates as
: an absolute value. If date2 not specified
: DIFF assumes the computation is relative
: to the current system date (%_date).
:
: Primitive function.
:
iff .%3==. then
set _$=%@eval[%@date[%_date]-%@date[%2]]
else
set _$=%@eval[%@date[%2]-%@date[%3]]
endiff
iff "%@substr[%_$,0,1]" EQ "-" then set _$=%@substr[%_$,1]
return
:DJD
: DJD - 4DATE DJD julianDate [year]
: Display Julian day as Date - convert Julian date to calander
: date. If no year is specified the current year is assumed.
:
: User level function
:
call 4date.btm j2d %2&
echo Calander Date: %_$
return
:DSTRUCT
: DSTRUCT - 4DATE DSTRUCT date dv1 dv2 dv3
: Returns a Date Structure.
: Takes date and returns with the environment
: varibles set to date values. The args dv1,2,3
: are the names of environment variables to
: contain the parts of the date, i.e. day, month, year.
:
: Primitive function
:
set %3=%@substr[%2,0,2]
set %4=%@substr[%2,3,2]
set %5=%@substr[%2,6,2]
return
:DOW
: DOW - 4DATE DOW [date [century]]
: Uses Zellers congruence to compute the day-of-the-week.
: DOW's implementation assumes US date conventions.
: Change the call to DSTRUCT in DOW to reorder the
: month and day variables as apporpriate to your
: date format.
: Primitive function
:
: cheat if no arg, i.e. today
iff .%2==. then
set _$=%_dow
return
endiff
: set up local stack data structures
set _d0=Sun
set _d1=Mon
set _d2=Tue
set _d3=Wed
set _d4=Thu
set _d5=Fri
set _d6=Sat
: this is ugly but necessary since 4DOS dates to not
: include the century.
iff "%3" EQ "" then
set _$c=19
else
set _$c=%3
endiff
: Change this call for different data formats
call 4date.btm dstruct %2 $m $d $y
iff "%$m" EQ "01" .OR. "%$m" EQ "02" then
set $m=%@eval[%$m + 12]
iff "%$y" GT "00" then
set $y=%@eval[%$y-1]
else
set %$y=99
set _$c=%@eval[%_$c-1]
endiff
endiff
set _$=%$d
: The following code implements Zellers algorithm.
set _$=%@eval[%_$+%@int[%@eval[((%$m+1)*26)/10]]]
set _$=%@eval[%_$+%$y]
: correct for leap years
set _$=%@eval[%_$+(%@int[%@eval[%$y/4]])]
: correct for leap centuries
set _$=%@eval[%_$+(%@int[%@eval[%_$c/4]])]
set _$=%@eval[%_$-%_$c-%_$c]
: while loop kludge
:LOOP
if %_$ GE 0 goto ENDLOOP
set _$=%@eval[%_$+7]
goto loop
:ENDLOOP
set _$=%@eval[%_$ %% 7]
if %_$ == 0 set _$=7
set _$=%@eval[%_$-1]
: return day-of-week
set _$=%[_d%[_$]]
: clean up local stack data
unset _$c
unset _d0
unset _d1
unset _d2
unset _d3
unset _d4
unset _d5
unset _d6
unset $d
unset $m
unset $y
return
:IS
: IS - 4DATE IS integer
: Displays the date for the given number of
: days into the past or future from today.
:
: User function.
:
call 4date.btm ddate %2 %_date
echo Date is: %_$
return
:J2D
: J2D - 4DATE J2D julianDate [year]
: Converts a Julian day to a calander date.
: If no year is specified the current year
: is assumed.
:
: Primitive function.
:
iff "%3" EQ "" then
set _$y=%@substr[%_date,6]
else
set _$y=%3
endiff
set _$=%@makedate[%@eval[%2+%@date[01-01-%_$y]-1]]
unset _$y
return
:FDOW
: FDOW - 4DATE FDOW [date]
: Fast Day-Of-Week, returns day-of-week FAST.
: CAUTION - this function may leave system date
: in an incorrect state if interrupted before
: it completes. I cheat by setting the system
: date to the date for which the DOW is desired,
: then resetting the date. DOW is slower, but
: safer if you absolutely depend on your system
: date being correct.
:
: Primitive function
:
iff .%2==. then
set _$=%_dow
else
set _$d=%_date
*date %2
set _$=%_dow
*date %_$d
unset _$d
endiff
return
:JDAY
: JDAY - 4DATE JDAY
: Displays todays "Julian" day of the year.
:
: User level function.
:
call 4date.btm cjul %_date
echo Julian date: %_$
return
:HELP
: HELP - Displays summary of 4DATE functions.
:
: User level function.
:
text
4DATE - Implements various useful date functions.
Primitives always return values in _$
Usage: 4DATE [function argument...]
CJUL - 4DATE CJUL date (Primitive function)
Return the "Julian" day of year for the specified date.
DDATE - 4DATE DDATE integer [aDate] (Primitive function)
DeltaDate returns the actual date for a given
number of days before or after a given date.
If aDate not specified todays date is default.
DIFF - 4DATE DIFF date1 [date2] (Primitive function)
Compute the absolute difference between two dates.
If date2 not specified DIFF assumes the computation
is relative to the current system date (%_date).
DJD - 4DATE DJD julianDate [year] (User level function)
Display Julian date as calander Date. If no year is
specified the current year is assumed.
DSTRUCT - 4DATE DSTRUCT date dv1 dv2 dv3 (Primitive function)
Takes a date and returns with the given environment
varibles set to date values.
DOW - 4DATE DOW [date [century]] (Primitive function)
Uses Zellers congruence to compute the day-of-the-week.
U.S. date form assumed (see function for changing this).
FDOW - Fast Day-Of-Week (Primitive function)
CAUTION - this function may leave system date
in an incorrect state if interrupted.
HELP - Displays this page.
IS - 4DATE IS integer (User level function)
Displays the date for the given number of
days into the past or future from today.
J2D - 4DATE J2D julianDate [year] (Primitive function)
Converts a Julian day to a calander date.
The current year is the default.
JDAY - 4DATE JDAY (User level function)
Displays todays "Julian" day of the year.
endtext